package com.lh.springcloud.alibaba.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lh.springcloud.alibaba.service.PaymentService;
import com.lh.springcloud.bean.CommonResult;
import com.lh.springcloud.bean.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
public class CircleBreakerController {

    //拿到提供者注册中心
    public static final String SERVICE_URL = "http://nacos-payment-provider";

    //OpenFeign
    @Autowired
    private PaymentService paymentService;

    @GetMapping(value = "/consumer/openfeign/{id}")
    @SentinelResource(value = "openfeign",fallback = "deal_paymentSQL")
    public CommonResult<Payment> paymentSQL(@PathVariable("id") Long id) {
        if(id == 4) {
            throw new RuntimeException("没有该id");
        }
        return paymentService.paymentSQL(id);
    }

    public CommonResult<Payment> deal_paymentSQL(Long id) {
        return new CommonResult<>(500, "运行时异常返回", new Payment(id, "errorSerial.."));
    }

}
